<?php
namespace app\api\controller;
use think\Controller;
use think\Request;
use app\api\model\DisposeModel;
use think\Db;
class Dispose extends Common
{
    /**
     * 个人信息
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function Information(Request $request,DisposeModel $model)
    {
        $token =$request->header('authorization');
        $list =$model->getInformation($token);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功', 'list' => $list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 个人信息 修改
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function InformationEdit($id,Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $list =$model->getInformationEdit($id,$data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功']);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 员工
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function Staff(Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $list =$model->getStaff($data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功', 'list' => $list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 员工新增
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function StaffAdd(Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $data['password'] =MD5($data['password']);
        $data['create_time'] =time();
        $data['entry_time'] =strtotime($data['entry_time']);
        $data['level'] =3;
        $data['status'] =0;
        $list =$model->getStaffAdd($data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功']);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 员工修改
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function StaffEdit($id,Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $data['password'] =MD5($data['password']);
        $list =$model->getStaffEdit($id,$data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功']);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 员工查找
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function StaffInfo($id,DisposeModel $model)
    {
        $list =$model->getStaffInfo($id);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功', 'list' => $list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 员工删除
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function StaffDel($id,DisposeModel $model)
    {
        $list =$model->getStaffDel($id);
        if ($list ==1) {
            return json(['code' => 500, 'msg' => '账号是系统管理员,无法删除']);
        } else if($list ==2){
            return json(['code' => 500, 'msg' => '帐号在系统中开具了单据,无法删除']);
        }else{
            return json(['code' => 200, 'msg' => '成功']);
        }
    }

    /**
     * 公司公告
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function Notice(Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $list =$model->getNotice($data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功', 'list' => $list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 公司公告---新增
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function NoticeAdd(Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $list =$model->getNoticeAdd($data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功']);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 公司公告----修改
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function NoticeEdit($id,Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $list =$model->getNoticeEdit($id,$data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功']);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 公司公告---查找
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function NoticeInfo($id,DisposeModel $model)
    {
        $list =$model->getNoticeInfo($id);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功', 'list' => $list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 公司公告---删除
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function NoticeDel($id,DisposeModel $model)
    {
        $list =$model->getNoticeDel($id);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功']);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 物流管理---列表
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    /*public function Logistic(Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $list =$model->getLogistic($data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功', 'list' => $list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }*/

    /**
     * 系统参数---
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function sys(DisposeModel $model)
    {
        $list =$model->getSys();
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功', 'list' => $list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    /**
     * 系统参数---修改
     * @param $id
     * @param Request $request
     * @param DisposeModel $model
     * @return \think\response\Json
     */
    public function sysEdit($id,Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $list =$model->getSysEdit($id,$data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功']);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }

    public function Log(Request $request,DisposeModel $model)
    {
        $data =$request->param();
        $data['start_time'] =isset($data['start_time']) ? strtotime($data['start_time']) : '';
        $data['end_time'] =isset($data['end_time']) ? strtotime($data['end_time']) : '';
        $list =$model->getLog($data);
        if (!empty($list)) {
            return json(['code' => 200, 'msg' => '成功','list'=>$list]);
        } else {
            return json(['code' => 500, 'msg' => '失败']);
        }
    }
}